{
 "cells": [
  {
   "metadata": {},
   "cell_type": "markdown",
   "source": "# reduce函数",
   "id": "ac121eff4795f4cb"
  },
  {
   "cell_type": "code",
   "id": "initial_id",
   "metadata": {
    "collapsed": true,
    "ExecuteTime": {
     "end_time": "2024-10-30T02:05:47.733189Z",
     "start_time": "2024-10-30T02:05:43.446485Z"
    }
   },
   "source": [
    "from functools import reduce\n",
    "res = reduce(lambda x, y: x * y, map(int, input().split()))\n",
    "print(res)"
   ],
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "6\n"
     ]
    }
   ],
   "execution_count": 2
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2024-10-30T02:47:30.229301Z",
     "start_time": "2024-10-30T02:47:30.226841Z"
    }
   },
   "cell_type": "code",
   "source": [
    "def seq():\n",
    "    a, b = 0, 1\n",
    "    while b < 1000:\n",
    "        yield b\n",
    "        a, b = b, a + b\n",
    "\n",
    "c = seq()\n",
    "print(list(c))\n",
    "res = reduce(lambda x, y: x + y, list(seq()), 0)\n",
    "print(res)"
   ],
   "id": "1214190a3385a368",
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377, 610, 987]\n",
      "2583\n"
     ]
    }
   ],
   "execution_count": 10
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 2
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython2",
   "version": "2.7.6"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
